import React from "react";
import { TreeSelect, DatePicker } from "antd";
import moment from "moment";
import styles from "./styles.module.less";
const dateFormat = "YYYY-MM-DD";
const arr = [
  {
    name: "1",
    amount: 100
  },
  {
    name: "1",
    amount: -100
  },
  {
    name: "1",
    amount: -5
  },
  {
    name: "1",
    amount: 100
  }
];
class Demo extends React.Component {
  constructor(props) {
    super(props);

    this.gouzao = function gouzaohanshu(name, age) {
      this.name = name;
      this.age = age;
    };
  }
  state = {
    value: "",
    treeData: [{ id: "33", pId: 0, value: "33", title: "浙江省", isLeaf: false }]
  };
  componentDidMount() {
    this.arrMap();
    this.arrChange();
  }
  genTreeNode = (parentId, isLeaf = false) => {
    const random = Math.random().toString(36).substring(2, 6);
    return [
      { id: random, pId: parentId, value: random, title: random + "杭州市", isLeaf: isLeaf },
      { id: random + "1", pId: parentId, value: random + "1", title: random + "嘉兴市", isLeaf: isLeaf },
      { id: random + "2", pId: parentId, value: random + "2", title: random + "温州市", isLeaf: isLeaf }
    ];
  };

  onLoadData = (treeNode) =>
    new Promise((resolve) => {
      const { id } = treeNode.props;
      setTimeout(() => {
        this.setState({
          treeData: this.state.treeData.concat(this.genTreeNode(id, false))
        });
        resolve();
      }, 300);
    });

  onChange = (value) => {
    console.log(value);
    this.setState({ value });
  };

  arrMap = () => {
    // let arrs =arr.filter(v=>v.amount<0)
    let arrs = arr.find((v) => v.amount < 0);
    if (arrs) {
      // alert("dddd")
      return;
    }
  };
  arrChange = () => {
    let arr = [1, 2, 3, 4, 5, 6, 6];
    let roleListCheck = [1, 2, 8, 4, 5, 5, 7];
    let test01 = arr.filter((v) => roleListCheck.indexOf(v) > -1);
    let test02 = roleListCheck.filter((v) => arr.indexOf(v) > -1);
    let test = [...new Set(test01.concat(test02))]; //es6方法
    console.log("test===", test);
  };
  test = (arr, data) => {
    let url = window.location.origin + "/html-samples_new/presentation_control.html";
    window.open(url);
  };

  render() {
    // let gouzaorender = new this.gouzao("wu", 24);
    // console.log("========", gouzaorender.name);
    const { treeData } = this.state;
    const arr = ["aaa", "ccc"];
    const data = {
      aaa: [
        { count: 31, date: "202010" },
        { count: 32, date: "202011" },
        { count: 33, date: "202012" },
        { count: 34, date: "202013" }
      ],
      bbb: [
        { count: 10, date: "202010" },
        { count: 12, date: "202011" },
        { count: 13, date: "202012" },
        { count: 14, date: "202013" }
      ],
      ccc: [
        { count: 21, date: "202010" },
        { count: 22, date: "202011" },
        { count: 23, date: "202012" },
        { count: 24, date: "202013" }
      ]
    };
    // console.log("treeData==", treeData);
    return (
      <div>
        <DatePicker value={moment("2015-06-06", dateFormat)} className={styles.dates} />
        <TreeSelect
          treeDataSimpleMode
          style={{ width: "100%" }}
          value={this.state.value}
          dropdownStyle={{ overflow: "auto" }}
          placeholder="Please select"
          onChange={this.onChange}
          loadData={this.onLoadData}
          treeData={treeData}
        />
      </div>
    );
  }
}
export default Demo;
